<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>별찍기</title>
	<script type="text/javascript">
	function starsLeft(){
		var star = "*";
		var idx = 1;
		var str = "";
		
		while(idx < 6){
			str = "";
			for ( var i = 0; i < 6; i++) {
			if(idx == i){break;}
					str += star;
			}
			str += "<br />";
			document.write(str);
			idx++;
		}
	}
	
	function starsRight(){
		var star = "*";
		var space = "&nbsp;";
		var idx = 6;
		var str = "";
		
		while(idx > 1){
			str = "";
			for ( var i = 1; i <= 6; i++) {
				if(idx <= i){
					str += star;
				}else{
					str += space;
				}
			}
			str += "<br />";
			document.write(str);
			idx--;
		}
	}

	function starsDia(){
		var star = "*";
		var row = 12;
		var col = 12;
		var spaceIdxCnt = 0;
		var doMinus = false;
		
		var strArr = new Array();
		
		
		for ( var i = 0; i < row; i++) {
			var arr = new Array();
			for ( var j = 0; j < col; j++) {
				
// 				좌측 ~ 중앙 별할당
				if(j >= (col/2) - spaceIdxCnt
				&& j <= (col/2)){
					arr.push("*");
				}else{
					arr.push("");
				}
				
// 				우측 별할당
				if((col/2) + spaceIdxCnt >= j
						&& j > (col/2)){
					arr.push("*");
				}else{
					arr.push("");
				}
				if(j == col){
					
				}
			}
			strArr.push(arr);
			
			for ( var j = 0; j < col; j++) {
				if(!strArr[i][j]){
					document.write("&nbsp;");
				}else{
					document.write(strArr[i][j]);
				}
			}
			document.write("<br />");
			
			if(spaceIdxCnt == col/2){
				doMinus = true;
			}
			
			if(doMinus){
				spaceIdxCnt--;
			}else{
				spaceIdxCnt++;
			}
		}
	}
	function starsCenter(){
		var star = "*";
		var row = 12;
		var col = 12;
		var spaceIdxCnt = 0;
		var doMinus = false;
		
		var strArr = new Array();
		
		
		for ( var i = 0; i < row; i++) {
			var arr = new Array();
			for ( var j = 0; j < col; j++) {
				
// 				좌측 ~ 중앙 별할당
				if(j >= (col/2) - spaceIdxCnt
				&& j <= (col/2)){
					arr.push("*");
				}else{
					arr.push("");
				}
				
// 				우측 별할당
				if((col/2) + spaceIdxCnt >= j
						&& j > (col/2)){
					arr.push("*");
				}else{
					arr.push("");
				}
				if(j == col){
					
				}
			}
			strArr.push(arr);
			
			for ( var j = 0; j < col; j++) {
				if(!strArr[i][j]){
					document.write("&nbsp;");
				}else{
					document.write(strArr[i][j]);
				}
			}
			document.write("<br />");
			
			if(spaceIdxCnt == col/2){
				doMinus = true;
			}
			
			if(doMinus){
// 				spaceIdxCnt--;
				break;
			}else{
				spaceIdxCnt++;
			}
		}
	}
	</script>

</head>
<body>
	<input type="button" value="좌삼각" onclick="starsLeft()" />
	<input type="button" value="우삼각" onclick="starsRight()" />
	<input type="button" value="중삼각" onclick="starsCenter()" />
	<input type="button" value="다야" onclick="starsDia()" />
	
	<div id="stars">
	
	</div>
</body>
</html>